package org.test.updownload;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 这是一个字符串输出为一个word
 * 肇明师兄 的同学要　的。。没啥用。。。
 * @author Administrator
 *
 */
public class DownloadServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub

		//设置输出的为word格式
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("application/msword");

	    // 写流文件到前端浏览器
//	    ServletOutputStream out = resp.getOutputStream();
	    PrintWriter pw = resp.getWriter();
	    
	    BufferedOutputStream bos = null;
//	    try {
	    	
//	      bos = new BufferedOutputStream(out);
	      
	      byte[] buff = new byte[2048];
	      int bytesRead;
	      
	      String b = "hello";
	      pw.write(b);
//	      bos.write(b.getBytes());
	      
	      
//	    } catch (IOException e) {
//	      throw e;
//	    } finally {
//	      if (bos != null)
//	        bos.close();
//	    }
		
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doGet(req, resp);
	}

	
}
